<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/module.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <div class="vtabs">
          <?php $module_row = 1; ?>
          <?php foreach ($modules as $module) { ?>
          <a href="#tab-module-<?php echo $module_row; ?>" id="module-<?php echo $module_row; ?>"><?php echo $tab_module . ' ' . $module_row; ?>&nbsp;<img src="view/image/delete.png" alt="" onclick="$('.vtabs a:first').trigger('click'); $('#module-<?php echo $module_row; ?>').remove(); $('#tab-module-<?php echo $module_row; ?>').remove(); return false;" /></a>
          <?php $module_row++; ?>
          <?php } ?>
          <span id="module-add"><?php echo $button_add_module; ?>&nbsp;<img src="view/image/add.png" alt="" onclick="addModule();" /></span> 
		</div>
        <?php $module_row = 1; ?>
        <?php foreach ($modules as $module) { ?>
        <div id="tab-module-<?php echo $module_row; ?>" class="vtabs-content">
          <div id="tabs-<?php echo $module_row; ?>" class="htabs">
			<?php if(isset($module['title'])) : ?>
            <?php foreach ($module['title'] as $key=>$value) { ?>
            <a id="tab-title-item-<?php echo $module_row; ?>-<?php echo $key; ?>" href="#tab-item-<?php echo $module_row; ?>-<?php echo $key; ?>"><?php echo $value; ?>&nbsp;<img src="view/image/delete.png" alt="" onclick="$('.htabs a:first').trigger('click'); $('#tab-title-item-<?php echo $module_row; ?>-<?php echo $key; ?>').remove(); $('#tab-item-<?php echo $module_row; ?>-<?php echo $key; ?>').remove(); return false;" /></a>
            <?php } ?>
			<?php endif;?>
			<?php $key = isset($module['title']) ? count($module['title']) - 1 : 0;?>
			<span class="tab-add"><?php echo $button_add_tab; ?>&nbsp;<img data-module-row="<?php echo $module_row; ?>" data-id="<?php echo $key+1; ?>" src="view/image/add.png" alt="" onclick="addTab(this);" /></span> 
		  </div>
		  <?php if(isset($module['title'])) : ?>
          <?php foreach ($module['title'] as $key=>$value) { ?>
          <div id="tab-item-<?php echo $module_row; ?>-<?php echo $key; ?>">
            <table class="form">
			  <tr>
                <td><?php echo $entry_title; ?></td>
                <td><input type="text" value="<?php echo $value;?>" name="treoden_productstabs_module[<?php echo $module_row; ?>][title][]" /></td>
              </tr>	
              <tr>
                <td><?php echo $entry_product_data; ?></td>
				<td><select name="treoden_productstabs_module[<?php echo $module_row; ?>][product_data][]"><option value="bestsellers" <?php if($module['product_data'][$key] == 'bestsellers') echo "selected='selected'";?>>Bestsellers</option><option value="featured" <?php if($module['product_data'][$key] == 'featured') echo "selected='selected'";?>>Featured</option><option value="latest" <?php if($module['product_data'][$key] == 'latest') echo "selected='selected'";?>>Latest</option><option value="specials" <?php if($module['product_data'][$key] == 'specials') echo "selected='selected'";?>>Specials</option><option value="most-popular" <?php if($module['product_data'][$key] == 'most-popular') echo "selected='selected'";?>>Most Popular</option><option value="top-rating" <?php if($module['product_data'][$key] == 'top-rating') echo "selected='selected'";?>>Top Rating</option></select></td>
              </tr>
			  <tr>
                <td><?php echo $limit; ?></td>
				<td><input type="text" value="<?php echo $module['limit'][$key];?>" name="treoden_productstabs_module[<?php echo $module_row; ?>][limit][]" /></td>
              </tr>
			  <tr><td><?php echo $size; ?></td><td><input type="text" value="<?php echo $module['width'][$key];?>" name="treoden_productstabs_module[<?php echo $module_row; ?>][width][]" /><input type="text" value="<?php echo $module['height'][$key];?>" name="treoden_productstabs_module[<?php echo $module_row; ?>][height][]" /></td></tr>
            </table>
          </div>
          <?php } ?>
		  <?php endif;?>
          <table class="form">
            <tr>
              <td><?php echo $entry_layout; ?></td>
              <td><select name="treoden_productstabs_module[<?php echo $module_row; ?>][layout_id]">
                  <?php foreach ($layouts as $layout) { ?>
                  <?php if ($layout['layout_id'] == $module['layout_id']) { ?>
                  <option value="<?php echo $layout['layout_id']; ?>" selected="selected"><?php echo $layout['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $layout['layout_id']; ?>"><?php echo $layout['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select></td>
            </tr>
            <tr>
              <td><?php echo $entry_position; ?></td>
              <td><select name="treoden_productstabs_module[<?php echo $module_row; ?>][position]">
                  <?php if ($module['position'] == 'content_top') { ?>
                  <option value="content_top" selected="selected"><?php echo $text_content_top; ?></option>
                  <?php } else { ?>
                  <option value="content_top"><?php echo $text_content_top; ?></option>
                  <?php } ?>
                  <?php if ($module['position'] == 'content_bottom') { ?>
                  <option value="content_bottom" selected="selected"><?php echo $text_content_bottom; ?></option>
                  <?php } else { ?>
                  <option value="content_bottom"><?php echo $text_content_bottom; ?></option>
                  <?php } ?>
                  <?php if ($module['position'] == 'column_left') { ?>
                  <option value="column_left" selected="selected"><?php echo $text_column_left; ?></option>
                  <?php } else { ?>
                  <option value="column_left"><?php echo $text_column_left; ?></option>
                  <?php } ?>
                  <?php if ($module['position'] == 'column_right') { ?>
                  <option value="column_right" selected="selected"><?php echo $text_column_right; ?></option>
                  <?php } else { ?>
                  <option value="column_right"><?php echo $text_column_right; ?></option>
                  <?php } ?>
                </select></td>
            </tr>
			<tr>
              <td><?php echo $entry_columns; ?></td>
              <td><input type="text" value="<?php echo $module['columns'];?>" name="treoden_productstabs_module[<?php echo $module_row; ?>][columns]" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_status; ?></td>
              <td><select name="treoden_productstabs_module[<?php echo $module_row; ?>][status]">
                  <?php if ($module['status']) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <option value="0"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select></td>
            </tr>
            <tr>
              <td><?php echo $entry_sort_order; ?></td>
              <td><input type="text" name="treoden_productstabs_module[<?php echo $module_row; ?>][sort_order]" value="<?php echo $module['sort_order']; ?>" size="3" /></td>
            </tr>
          </table>
        </div>
        <?php $module_row++; ?>
        <?php } ?>
      </form>
    </div>
  </div>
</div>
<style>
.htabs span{
    background: url("../image/tab.png") repeat-x scroll 0 0 #FFFFFF;
    border-left: 1px solid #DDDDDD;
    border-right: 1px solid #DDDDDD;
    border-top: 1px solid #DDDDDD;
    color: #000000;
    float: left;
    font-family: Arial,Helvetica,sans-serif;
    font-size: 13px;
    font-weight: bold;
    margin-right: 2px;
    padding: 7px 15px 6px;
    text-align: center;
    text-decoration: none;
}
.htabs span img,.htabs a img{vertical-align:middle;cursor:pointer}
</style>
<script type="text/javascript"><!--
var module_row = <?php echo $module_row; ?>;

function addModule() {	
	html  = '<div id="tab-module-' + module_row + '" class="vtabs-content">';
	html += '  <div id="tabs-<?php echo $module_row; ?>" class="htabs">';
    html += '    <span class="tab-add"><?php echo $button_add_tab; ?>&nbsp;<img data-module-row="<?php echo $module_row; ?>" data-id="1" src="view/image/add.png" alt="" onclick="addTab(this);" /></span>';
	html += '  </div>';
	html += '  <table class="form">';
	html += '    <tr>';
	html += '      <td><?php echo $entry_layout; ?></td>';
	html += '      <td><select name="treoden_productstabs_module[' + module_row + '][layout_id]">';
	<?php foreach ($layouts as $layout) { ?>
	html += '           <option value="<?php echo $layout['layout_id']; ?>"><?php echo addslashes($layout['name']); ?></option>';
	<?php } ?>
	html += '      </select></td>';
	html += '    </tr>';
	html += '    <tr>';
	html += '      <td><?php echo $entry_position; ?></td>';
	html += '      <td><select name="treoden_productstabs_module[' + module_row + '][position]">';
	html += '        <option value="content_top"><?php echo $text_content_top; ?></option>';
	html += '        <option value="content_bottom"><?php echo $text_content_bottom; ?></option>';
	html += '        <option value="column_left"><?php echo $text_column_left; ?></option>';
	html += '        <option value="column_right"><?php echo $text_column_right; ?></option>';
	html += '      </select></td>';
	html += '    </tr>';
	html += '	 <tr>';
	html += '	 <td><?php echo $entry_columns; ?></td>';
	html += '	 <td><input type="text" value="4" name="treoden_productstabs_module[' + module_row + '][columns]" /></td>';
	html += '    </tr>';
	html += '    <tr>';
	html += '      <td><?php echo $entry_status; ?></td>';
	html += '      <td><select name="treoden_productstabs_module[' + module_row + '][status]">';
	html += '        <option value="1"><?php echo $text_enabled; ?></option>';
	html += '        <option value="0"><?php echo $text_disabled; ?></option>';
	html += '      </select></td>';
	html += '    </tr>';
	html += '    <tr>';
	html += '      <td><?php echo $entry_sort_order; ?></td>';
	html += '      <td><input type="text" name="treoden_productstabs_module[' + module_row + '][sort_order]" value="" size="3" /></td>';
	html += '    </tr>';
	html += '  </table>'; 
	html += '</div>';
	
	$('#form').append(html);

	$('#module-add').before('<a href="#tab-module-' + module_row + '" id="module-' + module_row + '"><?php echo $tab_module; ?> ' + module_row + '&nbsp;<img src="view/image/delete.png" alt="" onclick="$(\'.vtabs a:first\').trigger(\'click\'); $(\'#module-' + module_row + '\').remove(); $(\'#tab-module-' + module_row + '\').remove(); return false;" /></a>');
	
	$('.vtabs a').tabs();
	
	$('#module-' + module_row).trigger('click');
	
	module_row++;
}
function addTab(obj) {
	var tab_id = $(obj).attr('data-id');
	var tab_module_row = $(obj).attr('data-module-row');
	html  = '<div id="tab-item-' + tab_module_row + '-' + tab_id + '">';
	html += '   <table class="form">';
	html +=		 ' <tr>';
    html +=            '<td><?php echo $entry_title; ?></td>';
    html +=            '<td><input type="text" value="Tab Title" name="treoden_productstabs_module[' + tab_module_row + '][title][]" /></td>';
    html +=          '</tr>	';
    html +=          '<tr>';
    html +=           '<td><?php echo $entry_product_data; ?></td>';
	html +=			'<td><select name="treoden_productstabs_module[' + tab_module_row + '][product_data][]"><option value="bestsellers">Bestsellers</option><option value="featured">Featured</option><option value="latest">Latest</option><option value="specials">Specials</option><option value="most-popular">Most Popular</option><option value="top-rating">Top Rating</option></select></td>';
	html +=			'<tr><td><?php echo $limit; ?></td><td><input type="text" value="10" name="treoden_productstabs_module[' + tab_module_row + '][limit][]" /></td></tr>';
	html +=			'<tr><td><?php echo $size; ?></td><td><input type="text" value="80" name="treoden_productstabs_module[' + tab_module_row + '][width][]" /><input type="text" value="80" name="treoden_productstabs_module[' + tab_module_row + '][height][]" /></td></tr>';
    html +=         ' </tr>';
    html +=       ' </table>';
	html += '</div>';
	
	$(obj).parent().parent().parent().children('table.form').before(html);

	$(obj).parent().before('<a id="tab-title-item-' + tab_module_row + '-' + tab_id + '" href="#tab-item-' + tab_module_row + '-' + tab_id + '">Tab Title&nbsp;<img src="view/image/delete.png" alt="" onclick="$(\'.htabs a:first\').trigger(\'click\'); $(\'#tab-title-item-' + tab_module_row + '-' + tab_id + '\').remove(); $(\'#tab-item-' + tab_module_row + '-' + tab_id + '\').remove(); return false;" /></a>');
	
	$('.htabs a').tabs();
	$(obj).parent().prev().trigger('click');
	tab_id = parseInt(tab_id)+ 1;
	$(obj).attr('data-id', tab_id);
}
//--></script> 
<script type="text/javascript"><!--
$('.vtabs a').tabs();
$('.htabs a').tabs();
//--></script>
<?php echo $footer; ?>